/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.cemaden.smp.controler;

import br.gov.cemaden.library.model.smp.ThreadsCPU;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

/**
 *
 * @author Simone Santos
 */
public class ThreadsCPUBean implements Serializable {

    ThreadsCPU t = new ThreadsCPU();

    public ThreadsCPUBean() {
    }

    public ThreadsCPU getThread() {
        Sigar sigar = new Sigar();

        DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

        try {
            String tThreadTotal = sigar.getThreadCpu().getTotal() / (3600 * 1000 * 24) + ":" + dateFormat.format(sigar.getThreadCpu().getTotal());
            String tThreadUser = sigar.getThreadCpu().getUser() / (3600 * 1000 * 24) + ":" + dateFormat.format(sigar.getThreadCpu().getUser());
            String tKernel = sigar.getThreadCpu().getSys() / (3600 * 1000 * 24) + ":" + dateFormat.format(sigar.getThreadCpu().getSys());

            t.setTempoCPUThreadTotal(tThreadTotal);
            t.setTempoCPUThreadUsuario(tThreadUser);
            t.setTempoCPUkernelThread(tKernel);

        } catch (SigarException se) {
            System.out.println("Erro no ThreadsCPUBean.setAllInformationThreadsCPU: " + se.getMessage() + " - " + se.getCause());
        }
        return t;
    }

    public void show(ThreadsCPU t) {
        System.out.println("TempoCPUThreadTotal: " + t.getTempoCPUThreadTotal());
        System.out.println("TempoCPUThreadUsuario: " + t.getTempoCPUThreadUsuario());
        System.out.println("TempoCPUkernelThread: " + t.getTempoCPUkernelThread());
        System.out.println("--------------------------------\n");
    }
}
